# -*- coding:utf-8 -*-
"""
动态平衡策略，香农
"""
from function.interface import *


class Strategy3(JyInterface):
    symbol = 'BTC/USDT'
    param = 0.05
    period = '10m'  
    def __init__(self, **kwargs):
        super(Strategy3,self).__init__(**kwargs)
        
    def loop(self):
        """策略部分"""
        usdt   = self.getSecondary(self.symbol)
        amount = self.getPosition(self.symbol)
        lastprice = self.getLastPrice(self.symbol)
        coinasset = lastprice * amount
        if coinasset/usdt-1 > self.param:
            self.sell(self.symbol, lastprice, (coinasset-usdt)/2/lastprice)
        elif coinasset/usdt-1 < -self.param:
            self.buy(self.symbol, lastprice, (usdt-coinasset)/2/lastprice)
    

if __name__ == "__main__":
    st = Strategy3(type_=1, futureOrSpot=0,appKey='e1165f79-ed2ht0-78937',secret='bf36b11829-c08f5',passphrase='',transferId=101)
    st.run(st.loop)
